package com.st.vmall.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import com.st.vmall.entity.JSONResult;
import com.st.vmall.util.UploadUtil;

@Controller
public class UploadController {

	@PostMapping("/upload.json")
	@ResponseBody
	public JSONResult upload(MultipartFile file,HttpServletRequest request) {
		
		String fileName = UploadUtil.saveFile(file, request, "upload");
		
		JSONResult result = new JSONResult();
		
		if(fileName != null) {
			//上传成功
			result.setCode(1);
			result.setMessage(fileName);
		}else {
			//上传失败
			result.setMessage("上传失败");
		}
		
		return result;
	}
	
}
